import "package:ct_pa_majordomo/config/theme_vars.dart";
import "package:ct_pa_majordomo/pages/device/entrance_guard/api.dart";
import "package:ct_pa_majordomo/pages/device/entrance_guard/face/widgets/add_face/index.dart";
import "package:ct_pa_majordomo/pages/device/entrance_guard/face/widgets/detail/index.dart";
import "package:ct_pa_majordomo/pages/device/entrance_guard/face/widgets/list_item.dart";
import "package:ct_pa_majordomo/pages/device/widgets/device_header.dart";
import "package:flutter/cupertino.dart";
import "package:flutter/material.dart";

class Face extends StatefulWidget {
  final Map? info;
  const Face({super.key, this.info});

  @override
  State<StatefulWidget> createState() => _FaceState();

}

class _FaceState extends State<Face> {

  final List<String> _items = ["重置人脸"];
  List _list = [];

  Future<void> _getPersonAll() async {
    Map resData = await entranceGuardApi.getRenters(widget.info?["faceLockId"]);
    setState(() {
      _list = resData["data"];
    });
  }

  @override
  void initState() {
    print(":LLLL<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>${widget.info}");
    _getPersonAll();
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return DeviceHeader(
        title: "人脸",
        leading: IconButton(
          icon: const Icon(Icons.arrow_back_ios_new),
          onPressed: () {
            Navigator.pop(context);
          },
        ),
        showSearch: false,
        showFloatBtn: false,
        actions: [
          DropdownButton(
            icon: const Padding(padding: EdgeInsets.only(right: 12), child: Icon(Icons.more_horiz, color: Colors.white,),),
            underline: const SizedBox(height: 0,),
            padding: EdgeInsets.all(0),
            onChanged: (value) {
              print(value);
            },
            items: _items.map((item) {
              return DropdownMenuItem(
                value: item,
                child: SizedBox(
                  height: 20,
                  child: Text(item),
                ),
              );
            }).toList(),
          ),
        ],
        // floatOnPress: () {
        //   Navigator.push(
        //     context,
        //     CupertinoPageRoute(
        //       builder: (BuildContext context) {
        //         return const AddFace();
        //       },
        //     ),
        //   );
        // },
        children: [
          Positioned(
              width: MediaQuery.of(context).size.width,
              top: 0,
              left: 0,
              child: Container(
                  width: MediaQuery.of(context).size.width,
                  decoration: const BoxDecoration(
                    color: Colors.white,
                  ),
                  padding: const EdgeInsets.symmetric(horizontal: ThemeVars.paddingPage, vertical: 6),
                  child: const SizedBox(
                    height: 40,
                    child: TextField(
                      decoration: InputDecoration(
                        border: OutlineInputBorder(
                            borderRadius: BorderRadius.all(Radius.circular(5)),
                            borderSide: BorderSide.none
                        ),
                        hintText: "请输入",
                        isDense: true,
                        filled: true,
                        fillColor: ThemeVars.colorBackground,
                        suffixIcon: SizedBox(
                          child: Icon(Icons.search, size: 20,),
                        ),
                      ),
                      style: TextStyle(fontSize: 14),
                    ),
                  )
              )
          ),
          Container(
            width: MediaQuery.of(context).size.width,
            margin: const EdgeInsets.only(top: 60, left: ThemeVars.paddingPage, right: ThemeVars.paddingPage),
            child: RefreshIndicator(
              onRefresh: _getPersonAll,
              child: _list.isNotEmpty ? ListView(
                children: List.generate(_list.length * 2 - 1, (index) {
                  if (index.isOdd) {
                    return const SizedBox(height: 12,);
                  }
                  Map faceInfo = _list[index ~/ 2];
                  return ListItem(
                    faceInfo: faceInfo,
                    onTap: () {
                      Navigator.push(
                        context,
                        CupertinoPageRoute(
                          builder: (BuildContext context) {
                            return Detail(info: faceInfo);
                          },
                        ),
                      );
                    },
                  );
                }),
              ) : Container(
                width: MediaQuery.of(context).size.width,
                padding: EdgeInsets.only(top: 60),
                child: Column(
                  children: [
                    Icon(Icons.hourglass_empty, size: 60, color: ThemeVars.colorPrimaryLight,),
                    Text("暂无数据",)
                  ],
                ),
              ),
            ),
          ),
        ]
    );
  }

}